/*    */ package com.zimbra.cs.util.tnef;
/*    */ 
/*    */ import com.zimbra.common.util.ByteUtil;
/*    */ import com.zimbra.cs.mime.MimeVisitor;
/*    */ import com.zimbra.cs.mime.MimeVisitor.VisitPhase;
/*    */ import java.io.IOException;
/*    */ import javax.mail.MessagingException;
/*    */ import javax.mail.Part;
/*    */ import javax.mail.internet.ContentType;
/*    */ import javax.mail.internet.MimeBodyPart;
/*    */ import javax.mail.internet.MimeMessage;
/*    */ import javax.mail.internet.MimeMultipart;
/*    */ import javax.mail.internet.MimePart;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class PlainTextFinder
/*    */   extends MimeVisitor
/*    */ {
/*    */   private MimePart mPlainTextPart;
/*    */   
/*    */   public String getPlainText()
/*    */     throws MessagingException, IOException
/*    */   {
/* 41 */     if (this.mPlainTextPart == null)
/* 42 */       return null;
/* 43 */     ContentType ct = new ContentType(this.mPlainTextPart.getContentType());
/* 44 */     String charset = ct.getParameter("charset");
/* 45 */     if (charset == null) charset = "us-ascii";
/* 46 */     byte[] descBytes = ByteUtil.getContent(this.mPlainTextPart.getInputStream(), this.mPlainTextPart.getSize());
/* 47 */     return new String(descBytes, charset);
/*    */   }
/*    */   
/*    */   private static boolean matchingType(Part part, String ct) throws MessagingException {
/* 51 */     String mmCtStr = part.getContentType();
/* 52 */     if (mmCtStr != null) {
/* 53 */       ContentType mmCt = new ContentType(mmCtStr);
/* 54 */       return mmCt.match(ct);
/*    */     }
/* 56 */     return false;
/*    */   }
/*    */   
/*    */   protected boolean visitBodyPart(MimeBodyPart bp) throws MessagingException
/*    */   {
/* 61 */     if ((this.mPlainTextPart == null) && (matchingType(bp, "text/plain")))
/* 62 */       this.mPlainTextPart = bp;
/* 63 */     return false;
/*    */   }
/*    */   
/*    */   protected boolean visitMessage(MimeMessage mm, MimeVisitor.VisitPhase visitKind) throws MessagingException
/*    */   {
/* 68 */     if ((this.mPlainTextPart == null) && (matchingType(mm, "text/plain")))
/* 69 */       this.mPlainTextPart = mm;
/* 70 */     return false;
/*    */   }
/*    */   
/*    */   protected boolean visitMultipart(MimeMultipart mp, MimeVisitor.VisitPhase visitKind) throws MessagingException
/*    */   {
/* 75 */     return false;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/util/tnef/PlainTextFinder.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */